package app;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

/*
 * Reads the item's information from the Jagex's database
 * Store the user's input also
 */
public class Reader {
	private String rawData;
	private String itemID;
	private String itemName;
	private String location;
	private String category;
	
	Reader(String location, String category, String itemName, String itemID) throws IOException {
		this.itemID = itemID;
		this.location = location;
		this.category = category;
		this.itemName = itemName;
		grabFromSite(itemID);
	}

	public String getItemID() {
		return itemID;
	}

	public String getItemName() {
		return itemName;
	}

	public String getCategory() {
		return category;
	}

	public String getLocation() {
		return location;
	}

	public String getRawData() {
		return rawData;
	}

	private void grabFromSite(String itemID) throws IOException {
		StringBuilder link = new StringBuilder(StrVar.URL.getVarName());
		link.append(itemID);
		link.append(StrVar.JSON.getVarName());
		BufferedReader readFromSite =
			new BufferedReader(new InputStreamReader(new URL(link.toString()).openStream()));
		rawData = readFromSite.readLine();
	}
}
